function check(){
	var i = 0;
	var ok = true;
	
	for(var loop = 0;loop < 13;loop++){
		document.getElementById("formerrors"+loop).innerHTML = "";
	}
	if(document.getElementById("username").value.length < 5){
		document.getElementById("formerrors"+i).innerHTML = "Gebruikersnaam \""+document.getElementById("username").value+"\" is te kort (5 of meer tekens nodig).";
		i++;
		ok = false;
	}
	if(document.getElementById("password1").value.length < 5){
		document.getElementById("formerrors"+i).innerHTML = "Wachtwoord is te kort (5 of meer tekens nodig).";
		i++;
		ok = false;
	}
	if(document.getElementById("password1").value != document.getElementById("password2").value){
		document.getElementById("formerrors"+i).innerHTML = "De ingevulde wachtwoorden zijn niet hetzelfde.";
		i++;
		ok = false;
	}
	if(document.getElementById("email").value.indexOf("@") == -1){
		document.getElementById("formerrors"+i).innerHTML = "Geen geldig email adres.";
		i++;
		ok = false;
	}
	if(document.getElementById("voornaam").value < 1){
		document.getElementById("formerrors"+i).innerHTML = "Voornaam niet ingevuld.";
		i++;
		ok = false;
	}
	if(document.getElementById("achternaam").value < 1){
		document.getElementById("formerrors"+i).innerHTML = "Achternaam niet ingevuld.";
		i++;
		ok = false;
	}
	if(document.getElementById("postcode").value < 6){
		document.getElementById("formerrors"+i).innerHTML = "Ongeldige postcode.";
		i++;
		ok = false;
	}
	if(document.getElementById("straatnaam").value < 1){
		document.getElementById("formerrors"+i).innerHTML = "Straatnaam niet ingevuld.";
		i++;
		ok = false;
	}
	if(document.getElementById("straatnummer").value < 1){
		document.getElementById("formerrors"+i).innerHTML = "Straatnummer is niet ingevuld.";
		i++;
		ok = false;
	}
	if(document.getElementById("plaats").value < 1){
		document.getElementById("formerrors"+i).innerHTML = "Plaats niet ingevuld.";
		i++;
		ok = false;
	}
	
	if(document.getElementById("land").options[document.getElementById("land").selectedIndex].value == "-"){
		document.getElementById("formerrors"+i).innerHTML = "Land niet ingevuld.";
		i++;
		ok = false;
	}
	if(document.getElementById("voorwaarden").checked == false){
		document.getElementById("formerrors"+i).innerHTML = "Niet akkoord gegaan met de voorwaarden.";
		i++;
		ok = false;
	}
	
	
	if(ok){
		document.getElementById("password").value = Sha1.hash(document.getElementById("password1").value, true);
		document.forms["registratieform"].submit();
	}
}

var cat1post = '';
var cat2post = '';
var cat3post = '';
var pagepost = 0;
var limitpost = 0;

function dropdownUpdate(selectBox, cat)
{
	//alert(" "+selectBox.options[selectBox.selectedIndex].value+"    "+cat);
	//updatePage();
	//alert(getElementById("productTable").text);
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			var response = xmlhttp.responseText;	
			//alert(response);
			var responseArray = response.split('\n');
			response = "";
			if(responseArray[0] == 1){
				var cat1 = document.getElementById("cat1");
				
				while(cat1.length > 0){
					cat1.remove(0);
				}
				var y=document.createElement('option');
				y.text = "Alle";
				cat1.add(y,null);
				for(var i = 1;i < responseArray.length - 1;i++){
					var y=document.createElement('option');
					y.text = responseArray[i];
					cat1.add(y,null);
				}
			}
			if(responseArray[0] == 2){
				var cat2 = document.getElementById("cat2");
				
				while(cat2.length > 0){
					cat2.remove(0);
				}
				var y=document.createElement('option');
				y.text = "Alle";
				cat2.add(y,null);
				for(var i = 1;i < responseArray.length - 1;i++){
					var y=document.createElement('option');
					y.text = responseArray[i];
					cat2.add(y,null);
				}
			}
			if(responseArray[0] == 3){
				var cat3 = document.getElementById("cat3");
				while(cat3.length > 0){
					cat3.remove(0);
				}
				var y=document.createElement('option');
				y.text = "Alle";
				cat3.add(y,null);
				for(var i = 1;i < responseArray.length - 1;i++){
					var y=document.createElement('option');
					y.text = responseArray[i];
					cat3.add(y,null);
				}
			}
		}
	}
	if(cat == 1){
		xmlhttp.open("GET","cat.php?cat="+cat,true);
	} 
	if(cat == 2){
		xmlhttp.open("GET","cat.php?cat="+cat+"&catValue1="+document.getElementById("cat1").options[document.getElementById("cat1").selectedIndex].text,true);
	}
	if(cat == 3){
		xmlhttp.open("GET","cat.php?cat="+cat+"&catValue1="+document.getElementById("cat1").options[document.getElementById("cat1").selectedIndex].text+"&catValue2="+document.getElementById("cat2").options[document.getElementById("cat2").selectedIndex].text,true);
	}
	xmlhttp.send();
}

function updatePage(){
/*
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp2=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		xmlhttp2=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp2.onreadystatechange=function()
	{
		if (xmlhttp2.readyState==4 && xmlhttp.status==200)
		{
			var response = xmlhttp2.responseText;		
			var responseArray = response.split('\n');
			response = "";
			//alert(responseArray[8]);
			for(var i = 0;i < responseArray.length;i++){
				//getElementById(i+"image").img = "/images/producten/"+responseArray[i*1];
			}
		}
	}
	xmlhttp2.open("GET","prod.php?page=2&limit=10&where=and cat1='Geluid'",true);
	xmlhttp2.send();
*/
}

function pageChange(page){
	cat1 = document.getElementById("cat1");
	cat2 = document.getElementById("cat2");
	cat3 = document.getElementById("cat3");
	limit = document.getElementById("limit").options[document.getElementById("limit").selectedIndex].value;
	var cat1Value = cat1.options[cat1.selectedIndex].value;
	var cat2Value = cat2.options[cat2.selectedIndex].value;
	var cat3Value = cat3.options[cat3.selectedIndex].value;
	
	
	if(cat1Value == "Alle" || cat1Value == "-"){
		//alert("No cat1 value");
		window.location.href = "producten.php?limit="+limit+"&page="+page;
	} else {
		//alert("Found cat1 value");
		if(cat2Value == "Alle" || cat2Value == "-"){
			//alert("No cat1 value");
			window.location.href = "producten.php?limit="+limit+"&page="+page+"&cat1="+cat1Value;
		} else {
			//alert("Found cat2 value");
			if(cat3Value == "Alle" || cat3Value == "-"){
				//alert("No cat1 value");
				window.location.href = "producten.php?limit="+limit+"&page="+page+"&cat1="+cat1Value+"&cat2="+cat2Value;
			} else {
				//alert("Found cat3 value");
				window.location.href = "producten.php?limit="+limit+"&page="+page+"&cat1="+cat1Value+"&cat2="+cat2Value+"&cat3="+cat3Value;
			}
		}
	}
}

function submitlogin(){
	var sha1 = Sha1.hash(document.getElementById("passwordfield").value, true);
	document.getElementById("password").value = sha1;
	document.forms["loginform"].submit();
}
function submituser(){

	
	if(document.getElementById("nieuwwachtwoord1").value == document.getElementById("nieuwwachtwoord2").value){
		if(document.getElementById("huidigwachtwoord").value != ""){
			var sha1 = Sha1.hash(document.getElementById("huidigwachtwoord").value, true);
			document.getElementById("password").value = sha1;
			sha1 = Sha1.hash(document.getElementById("nieuwwachtwoord1").value, true);
			document.getElementById("nieuwwachtwoord").value = sha1;
		}
		document.forms["userform"].submit();
	} else {
		alert("Wachtwoorden zijn niet hetzelfde.");
	}
}
function handleEnter(inField, e) {
    var charCode;
    
    if(e && e.which){
        charCode = e.which;
    }else if(window.event){
        e = window.event;
        charCode = e.keyCode;
    }

    if(charCode == 13) {
        submit();
    }
}
function handleEnter(inField, e) {
    var charCode;
    
    if(e && e.which){
        charCode = e.which;
    }else if(window.event){
        e = window.event;
        charCode = e.keyCode;
    }

    if(charCode == 13) {
        submit();
    }
}
function getadres(klantnummer, adresbox){
	var adresnummer = adresbox.options[adresbox.selectedIndex].value;
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp3=new XMLHttpRequest();
	} else {// code for IE6, IE5
		xmlhttp3=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp3.onreadystatechange=function(){
		if (xmlhttp3.readyState==4 && xmlhttp3.status==200){
			var response = xmlhttp3.responseText;
			//alert(response);
			var responseArray = response.split('\n');
			response = "";
			document.getElementById("plaats").value = responseArray[0];
			document.getElementById("straat").value = responseArray[1];
			document.getElementById("straatnummer").value = responseArray[2];
			document.getElementById("postcode").value = responseArray[3];
			var landbox = document.getElementById("land");
			for(var i = 0;i < landbox.length;i++){
				if(landbox.options[i].toString() == responseArray[4].toString()){
					landbox.selectedIndex = i;
				}
			}
		}
	}
	if(adresnummer == "Nieuw adres"){
			document.getElementById("plaats").value = "";
			document.getElementById("straat").value = "";
			document.getElementById("straatnummer").value = "";
			document.getElementById("postcode").value = "";
	} else {
		xmlhttp3.open("GET","getadres.php?klantnummer="+klantnummer+"&adresnummer="+adresnummer,true);
		xmlhttp3.send();
	}
}